import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

// 空或加载视图组件
class EmptyOrLoading extends StatelessWidget {
  final bool isLoading;
  final bool isEmpty;
  final Widget child;
  final String emptyMessage;

  const EmptyOrLoading({
    super.key,
    required this.isLoading,
    required this.isEmpty,
    required this.child,
    this.emptyMessage = '暂无数据',
  });

  @override
  Widget build(BuildContext context) {
    if (isLoading) {
      return Center(
        child: Loading.loadingWidget(),
      );
    }

    if (isEmpty) {
      return Center(
        child: Transform.translate(
          offset: const Offset(0, -50),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Image.asset(
                LxR.empty_png,
                package: PACKAGE_NAME,
                width: 240.w,
                height: 240.w,
              ),
              SizedBox(height: 10.w),
              Padding(
                padding: EdgeInsets.only(
                    left: CONTENT_MARGIN * 2, right: CONTENT_MARGIN * 2),
                child: LxText(
                  emptyMessage,
                  fontWeightEnum: LxFontWeightEnum.bodyLarge,
                  color: Colors.white.withOpacity(0.7),
                  lineHeight: 1.4,
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        ),
      );
    }

    return child;
  }
}
